//
//  TWAllCategoriesSquareCardCell.swift
//  EyepetizerImitative
//
//  Created by 田伟 on 2017/4/18.
//  Copyright © 2017年 个人. All rights reserved.
//

import UIKit
import SDWebImage

class TWAllCategoriesSquareCardCell: UICollectionViewCell {

    @IBOutlet weak var backImageView: UIImageView!
    @IBOutlet weak var titlesLabel: UILabel!
    
    @IBOutlet weak var coverView: UIView!
    var model : TWAllCategoriesModel?{
        didSet {
            guard let model = model else {
                return
            }
            let url = model.image
            guard let url1 =  url else {
                return
            }
            backImageView.sd_setImage(with: URL(string: url1))
            
            let text = model.title
            if text == "" {
                coverView.isHidden = true
            } else {
                coverView.isHidden = false
            }
            titlesLabel.text = text
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        let longpress = UILongPressGestureRecognizer(target: self, action: #selector(coverViewLongpress(longpress : )))
        coverView.addGestureRecognizer(longpress)
    }
    @objc fileprivate func coverViewLongpress(longpress : UILongPressGestureRecognizer){
        if longpress.state == .began {
            UIView.animate(withDuration: 0.5, animations: {
                self.titlesLabel.alpha = 0
                self.coverView.alpha = 0
            })
        } else if longpress.state == .ended {
            UIView.animate(withDuration: 0.25, animations: {
                self.titlesLabel.alpha = 1
                self.coverView.alpha = 0.5
            })
        }
    }
}
